package c.j.a.d.b.m;

import android.util.SparseArray;
import c.j.a.d.b.e.b;
import c.j.a.d.b.h.c;
import c.j.a.d.b.l.a;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/* compiled from: DownloadThreadPool */
public class d {
    public volatile SparseArray<c> a = new SparseArray();
    public int b = 0;

    public final void a() {
        try {
            ArrayList arrayList = new ArrayList();
            for (int i = 0; i < this.a.size(); i++) {
                int keyAt = this.a.keyAt(i);
                if (!((c) this.a.get(keyAt)).l.get()) {
                    arrayList.add(Integer.valueOf(keyAt));
                }
            }
            for (int i2 = 0; i2 < arrayList.size(); i2++) {
                Integer num = (Integer) arrayList.get(i2);
                if (num != null) {
                    this.a.remove(num.intValue());
                }
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public final void b(c cVar) {
        try {
            ExecutorService s = b.s();
            c cVar2 = cVar.b;
            if (cVar2 != null) {
                com.ss.android.socialbase.downloader.g.c cVar3 = cVar2.a;
                if (cVar3 != null) {
                    int Z = cVar3.Z();
                    if (Z == 3) {
                        s = b.r != null ? b.r : b.s();
                    } else if (Z == 4) {
                        s = b.s != null ? b.s : b.s();
                    }
                }
            }
            if (s != null && (s instanceof ThreadPoolExecutor)) {
                ((ThreadPoolExecutor) s).remove(cVar);
                if (a.d(cVar.E()).k("pause_with_interrupt", false)) {
                    Future future = cVar.a;
                    if (future != null) {
                        future.cancel(true);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
